const session=require("express-session");
const FileStore = require('session-file-store')(session)
var uid = require('uid-safe').sync

function init(name=null,type=null){
    var options={}
    if(name){
        options.name=name;
        if(type=='query')options.genid=function(req){
            let query= req.query;
            if (typeof query[name] === null || query[name] === ''){      
              return uid(24); 
            }else return query[name]   
        };
        else if(type == 'header')options.genid=function(req){
            let header= req.header['x'];
            if (typeof header === null || header === ''){      
              return uid(24); 
            }else return header   
        }
    }
    options.secret="keyboard cat";
    options.resave=false
    options.saveUninitialized=false
    options.cookie={maxAge:300000,secure:false,httpOnly:true}
    //options.store=new FileStore()
    return session(options)
}

module.exports = init;